import http from "@/utils/http";

/**
 * 分页查询文章
 * @param {number} pageNum
 * @param {number} pageSize
 * @param {number} categoryId
 * @param {string} state
 * @returns
 */
export const getArticlesAPI = (pageNum, pageSize, categoryId, state) => {
  let str = `pageNum=${pageNum}&pageSize=${pageSize}`;
  if (categoryId && categoryId !== "0") {
    str += `&categoryId=${categoryId}`;
  }
  if (state && state !== "0") {
    str += `&state=${state}`;
  }
  return http.get(`/article?${str}`);
};

/**
 * 新增文章
 * @param {*} data
 * @returns
 */
export const addArticleAPI = data => {
  return http.post("/article", data);
};

export const updateArticleAPI = data => {
  return http.put("/article", data);
};

/**
 * 删除文章
 * @param {number} id
 * @returns
 */
export const deleteArticleAPI = id => {
  return http.delete(`/article?id=${id}`);
};
